package com.bokee.archerwq.lab.pattern.singleton;

/**
 * The standard method to implement Singletons in Java. The technique is known
 * as the initialization on demand holder idiom, is as lazy as possible, and
 * works in all known versions of Java. It takes advantage of language
 * guarantees about class initialization, and will therefore work correctly in
 * all Java-compliant compilers and virtual machines.
 * 
 * @author Johnny 2011-10-9
 */
public class TrueSingleton {

	// Private constructor prevents instantiation from other classes
	private TrueSingleton() {
	}

	/**
	 * SingletonHolder is loaded on the first execution of
	 * Singleton.getInstance() or the first access to SingletonHolder.INSTANCE,
	 * not before.
	 */
	private static class SingletonHolder {
		private static final TrueSingleton INSTANCE = new TrueSingleton();
	}

	public static TrueSingleton getInstance() {
		return SingletonHolder.INSTANCE;
	}

}
